<?php require_once('Connections/learnConn.php');

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

  $colname_jadwal = $_GET['kelas'];
  $colname_jadwal2 = $_GET['subkelas'];
  $colname = $_GET['ta'];
mysql_select_db($database_learnConn, $learnConn);
$query_jadwal = sprintf("SELECT * FROM jadwal WHERE kd_kelas=%s AND kd_kat_kelas=%s AND tahun_ajaran=%s ", 
						GetSQLValueString($colname_jadwal, "text"), 
						GetSQLValueString($colname_jadwal2, "text"), 
						GetSQLValueString($colname, "text"));

$jadwal = mysql_query($query_jadwal, $learnConn) or die(mysql_error());
$row_jadwal = mysql_fetch_assoc($jadwal);
$totalRows_jadwal = mysql_num_rows($jadwal);
$rata = 0;
 
#setting judul laporan dan header tabel
/*
if ($totalRows_nilai !=0) {
	$judul = "Hasil Untuk Nilai ".$_GET['nis']." Ditemukan Untuk Tahun Ajaran ".$_GET['ta']." Semester ".$_GET['smt'];
} else {
	$judul = "Hasil Untuk Nilai ".$_GET['nis']." Tidak Ditemukan Untuk Tahun Ajaran ".$_GET['ta'];
}
*/
$judul = 'Jadwal Pelajaran kelas '.$colname_jadwal.'-'.$colname_jadwal2.' Tahun Ajaran '.$colname ;
$header = array(
		array("label"=>"Mata Pelajaran", "length"=>80, "align"=>"L"),
		array("label"=>"Ulangan", "length"=>40, "align"=>"L"),
		array("label"=>"Tugas", "length"=>30, "align"=>"L"),
		array("label"=>"UTS", "length"=>30, "align"=>"L")
	);	
#sertakan library FPDF dan bentuk objek
require_once ("fpdf/fpdf.php");
$pdf = new FPDF('p','mm','A4');
$pdf->AddPage(); 
#tampilkan judul laporan
$pdf->SetFont('Arial','','14');
$pdf->Cell(0,20, $judul, '0', 1, 'C'); 
#buat header tabel
$pdf->SetFont('Arial','','10');
$pdf->SetTextColor(0);
//$pdf->SetDrawColor(128,0,0);
//foreach ($header as $kolom) {
	//$pdf->Cell($kolom['length'], 5, $kolom['label'], 1, '0', $kolom['align'], true);
//}
$pdf->SetFillColor(222,222,222);
$pdf->Cell(10, 10, '', 0, '0', 'C', false);
$pdf->Cell(40, 10, 'Waktu', 1, '0', 'C', true);
$pdf->Cell(40, 10, 'Ulangan', 1, '0', 'C', true);
$pdf->Cell(60, 10, 'Tugas', 1, '0', 'C', true);
$pdf->Cell(30, 10, 'Kelas', 1, '0', 'C', true);
$pdf->Cell(1, 5, '', 0, '0', 'C', false); //tambahan

$pdf->Ln();
$pdf->Cell(40, 5, '', 0, '0', 'C', false);
$pdf->SetFillColor(0,255,0);
$pdf->Cell(40, 5, '', 0, '0', 'C', false);
$pdf->Cell(60, 5, '', 0, '0', 'C', false);
$pdf->Cell(30, 5, '', 0, '0', 'C', false);

#tampilkan data tabelnya
$pdf->SetFillColor(255,255,255);
$pdf->SetTextColor(0);
$pdf->SetFont('Arial','','10');
//$pdf->Ln();
$pdf->Ln();
$rata = 0;
do { 
	$colname_matpell = $row_nilai['kd_matpel'];
	mysql_select_db($database_learnConn, $learnConn);
	$query_matpell = sprintf("SELECT * FROM matpel WHERE kd_matpel = %s", GetSQLValueString($colname_matpell, "text"));
	$matpell = mysql_query($query_matpell, $learnConn) or die(mysql_error());
	$row_matpell = mysql_fetch_assoc($matpell);
	$totalRows_matpell = mysql_num_rows($matpell);
		//echo $row_matpell['nama_matpel'];
	//echo $row_nilai['ul1'];
	$pdf->Cell(10, 10, '', 0, '0', 'C', false);
	$pdf->Cell(40, 7, '   ' . $row_jadwal['hari'] . ',' . $row_jadwal['jam'] , 1, '0', 'L', true);
	//$pdf->Cell(12, 5, $row_matpell['ul1'], 1, '0', 'C', true);
	//2 $pdf->Cell(10, 6, $row_nilai['ul1'], 1,'0','C',true);
	
	//echo $row_jadwal['hari']; 
	//echo $row_jadwal['jam'];
	
$colname_matpel = $row_jadwal['kd_matpel'];
mysql_select_db($database_learnConn, $learnConn);
$query_matpel = sprintf("SELECT * FROM matpel WHERE kd_matpel = %s", GetSQLValueString($colname_matpel, "text"));
$matpel = mysql_query($query_matpel, $learnConn) or die(mysql_error());
$row_matpel = mysql_fetch_assoc($matpel);
$totalRows_matpel = mysql_num_rows($matpel);

	$pdf->Cell(40, 7, $row_matpel['nama_matpel'] , 1, '0', 'C', true);
	  //echo $row_matpel['nama_matpel']; 
	  
$colname_guru = $row_jadwal['nik'];
mysql_select_db($database_learnConn, $learnConn);
$query_guru = sprintf("SELECT nama FROM pegawai WHERE nik = %s", GetSQLValueString($colname_guru, "text"));
$guru = mysql_query($query_guru, $learnConn) or die(mysql_error());
$row_guru = mysql_fetch_assoc($guru);
$totalRows_guru = mysql_num_rows($guru);

	
	$pdf->Cell(60, 7, $row_guru['nama'] , 1, '0', 'C', true);	
	$pdf->Cell(30, 7, $row_jadwal['kd_kelas'] . '-' . $row_jadwal['kd_kat_kelas'], 1, '0', 'C', true);	
	$pdf->Ln();
	
} while ($row_jadwal = mysql_fetch_assoc($jadwal));
	$total = 'Rata-rata     =';
	
	$ratarata=0;
	if($totalRows_nilai != 0) {
	$ratarata = $rata / $totalRows_nilai; 
	$ratarata = number_format($ratarata , 2); 
	} else {
		//echo $ratarata;
	}
	  
	$pdf->Cell(40,10,'',0,0,'L'); 
	$pdf->Cell(50,10,'',0,0,'C');
	$pdf->Cell(50,10,'',0,0,'C');
	$pdf->Cell(15,10,'',0,0,'C');
	//$pdf->Cell(15,10,$total,0,0,'C');	
	//$pdf->Cell(20,10,$ratarata,0,0,'C');	
	//sy dah ada silincer nya, tinggal pipa na :D
	
/*
foreach ($data as $baris) {
	$i = 0;
	foreach ($baris as $cell) {
		$pdf->Cell($header[$i]['length'], 5, $cell, 1, '0', $kolom['align'], $fill);
		$i++;
	}
	$fill = !$fill;
	$pdf->Ln();
}
*/
#output file PDF
$pdf->Output();
?>
</body>
</html>